package com.help10000.rms.mvp.presenter

import com.amir.common.api.CustomObserver
import com.amir.common.beans.BaseResult
import com.amir.common.mvp.model.Model
import com.amir.common.mvp.presenter.BasePresenter
import com.amir.common.utils.Constant
import com.amir.common.utils.SPUtils
import com.amir.common.utils.ToastUtil
import com.help10000.rms.mvp.view.UpdateUserInfoView

class UpdateUserInfoPresenter(view: UpdateUserInfoView) : BasePresenter<UpdateUserInfoView>(view) {


    fun updatePwd(oldpwd: String, newpwd: String) {
        val AccessToken = SPUtils.getString(Constant.AccessToken)


        val changePwd = Model.getServer().changePwd(AccessToken, oldpwd, newpwd)
        Model.getObservable(changePwd, object : CustomObserver<BaseResult>(mvpView) {

            override fun success(t: BaseResult) {

                mvpView?.onSuccess()
            }
        })
    }

    /**
     * 修改昵称
     */
    fun updateNickname(nickname: String) {
        if (nickname.isBlank()) {
            ToastUtil.show("昵称不能为空")
            return;
        }
        val AccessToken = SPUtils.getString(Constant.AccessToken)
        val updateNickname = Model.getServer().updateNickname(AccessToken, nickname)
        Model.getObservable(updateNickname, object : CustomObserver<BaseResult>(mvpView) {

            override fun success(t: BaseResult) {
                mvpView?.onSuccess()
            }
        })
    }
}